package com.tarena.lbs.stock.web.rpc;

import com.tarena.lbs.pojo.stock.param.CouponStockParam;
import com.tarena.lbs.stock.api.StockApi;
import com.tarena.lbs.stock.web.service.StockService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@DubboService
@Component
@Slf4j
public class StockApiImpl implements StockApi {
    @Autowired
    private StockService stockService;
    @Override
    public boolean initCouponStock(CouponStockParam param) {
        try{
            return stockService.initCouponStock(param);
        }catch (Exception e){
            log.error("初始化优惠券库存失败,",e);
        }
        return false;
    }

    @Override
    public boolean checkEnoughStock(Integer couponId) {
        try{
            return stockService.checkEnoughStock(couponId);
        }catch (Exception e){
            log.error("检查当前优惠券:{}剩余库存失败",couponId,e);
        }
        return false;
    }

    @Override
    public boolean reduceStock(Integer couponId) {
        try{
            return stockService.reduceStock(couponId);
        }catch (Exception e){
            log.error("对当前优惠券:{}减库存失败",couponId,e);
        }
        return false;
    }
}
